#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

class BestEffortPublisher : public rclcpp::Node {
public:
  BestEffortPublisher() : Node("best_effort_publisher_node") {
    auto qos = rclcpp::QoS(rclcpp::KeepLast(10)).best_effort();
    publisher_ =
        this->create_publisher<std_msgs::msg::String>("best_effort_topic", qos);
    timer_ = this->create_wall_timer(
        std::chrono::seconds(1),
        std::bind(&BestEffortPublisher::timer_callback, this));
  }

  void timer_callback() {
    auto message = std_msgs::msg::String();
    message.data = "Hello, Best Effort!";
    RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
    publisher_->publish(message);
  }

private:
  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<BestEffortPublisher>());
  rclcpp::shutdown();
  return 0;
}